package com.wandian.weather.tools;

import android.content.Context;
import android.text.TextUtils;

import com.mylib.libcore.utils.UIUtils;
import com.wandian.weather.R;
import com.wandian.weather.bean.AqiBean;

/**
 * Created by xxq on 2017/8/9 0009.
 * 天气相关的工具
 */

public class WeatherUtil {

    /**
     * 根据空气质量返回相关参数
     * <p>
     * 标准：http://210.72.1.216:8080/gzaqi/Document/aqijsgd.pdf 在这里找到的
     * @param context
     * @param AQI
     * @return
     */
    public static AqiBean getAqiBean(Context context, int AQI) {
        AqiBean aqiBean = new AqiBean();
        String aqiString = "";

        int AqiColor = 0;
        if (AQI >= 0 && AQI <= 50) {
            aqiString = "优";
            AqiColor = R.color.aqi_1;
        } else if (AQI >= 51 && AQI <= 100) {
            aqiString = "良";
            AqiColor = R.color.aqi_2;
        } else if (AQI >= 101 && AQI <= 150) {
            AqiColor = R.color.aqi_3;
            aqiString = "轻度";
        } else if (AQI >= 151 && AQI <= 200) {
            AqiColor = R.color.aqi_4;
            aqiString = "中度";
        } else if (AQI >= 201 && AQI <= 300) {
            aqiString = "重度";
            AqiColor = R.color.aqi_5;
        } else if (AQI > 300) {
            aqiString = "严重";
            AqiColor = R.color.aqi_6;
        }

        AqiColor = context.getResources().getColor(AqiColor);
        aqiBean.setAqi(AQI)
                .setAqiColor(AqiColor)
                .setAqiName(aqiString);
        return aqiBean;
    }


    /**
     * 根据天气状态返回对应夜间的图标
     * @param weatherState
     * @return
     */
    public static Integer getWeatherStateImage(String weatherState, boolean isNight) {
        
        int drawable = 0;
        if (UIUtils.isEmpty(weatherState)) {
            drawable =isNight ? R.drawable.img_yintian: R.drawable.img_yintian;
         
        } else {
            switch (weatherState) {
                case "0":
                    drawable =isNight ? R.drawable.img_taiyang:R.drawable.img_taiyang;
                    break;
                case "晴":
                    drawable =isNight ? R.drawable.img_taiyang:R.drawable.img_taiyang;
                    break;
                case "多云":
                    drawable =isNight ? R.drawable.img_duoyun:R.drawable.img_duoyun;
                    break;
                case "小雨":
                    drawable =isNight ? R.drawable.img_xiaoyu:R.drawable.img_xiaoyu;
                    break;
                case "阴":
                    drawable =isNight ? R.drawable.img_yintian:R.drawable.img_yintian;
                    break;
                case "小雪":
                    drawable =isNight ? R.drawable.img_xiaoxue:R.drawable.img_xiaoxue;
                    break;
                case "1":
                    drawable = isNight ? R.drawable.img_duoyun:R.drawable.img_duoyun;
              
                    break;
                case "2":
                    drawable = isNight ? R.drawable.img_yintian:R.drawable.img_yintian;
                 
                    break;
                case "风":
                    drawable = isNight ? R.drawable.img_feng :R.drawable.img_feng;
                  
                    break;
                case "3":
                    drawable =  isNight ? R.drawable.img_zhenyu :R.drawable.img_zhenyu;
                  
                    break;
                case "雷雨":
                    drawable =  isNight ? R.drawable.img_leiyu :R.drawable.img_leiyu;
                    
                    break;
                case "暴雨":
                    drawable =  isNight ? R.drawable.img_baoyu :R.drawable.img_baoyu;
                    break;
                case "冰雹":
                    drawable =  isNight ? R.drawable.img_bingbao :R.drawable.img_bingbao;
                    break;
                case "4":
                    drawable =  isNight ? R.drawable.img_leizhenyu :R.drawable.img_leizhenyu;
                    break;
                case "雷阵雨":
                    drawable =  isNight ? R.drawable.img_leizhenyu :R.drawable.img_leizhenyu;
                    break;
                case "6":
                    drawable =  isNight ? R.drawable.img_yujiaxue :R.drawable.img_yujiaxue;
                    break;
                case "雨夹雪":
                    drawable =  isNight ? R.drawable.img_yujiaxue :R.drawable.img_yujiaxue;
                    break;
                case "冻雨":
                    drawable = isNight ? R.drawable.img_dongyu :R.drawable.img_dongyu;
                    break;
                case "7":
                    drawable = isNight ? R.drawable.img_xiaoyu : R.drawable.img_xiaoyu;
                    break;
                case "8"://也就是中雨
                    drawable =isNight ? R.drawable.img_zhongyu : R.drawable.img_zhongyu;
                    break;
                case "中雨":
                    drawable =isNight ? R.drawable.img_zhongyu : R.drawable.img_zhongyu;
                    break;
                case "9":
                    drawable =isNight ? R.drawable.img_dayu :  R.drawable.img_dayu;
                    break;
                case "大雨":
                    drawable =isNight ? R.drawable.img_dayu : R.drawable.img_dayu;
                    break;
                case "10":
                    drawable = isNight ? R.drawable.img_baoyu :R.drawable.img_baoyu;
                    break;
                case "14":
                    drawable = isNight ? R.drawable.img_xiaoxue :R.drawable.img_xiaoxue;
                    break;

                case "雪":
                    drawable = isNight ? R.drawable.img_zhongxue :R.drawable.img_zhongxue;
                   
                    break;
                case "15":
                    drawable = isNight ? R.drawable.img_zhongxue :R.drawable.img_zhongxue;
                    break;
                case "中雪":
                    drawable = isNight ? R.drawable.img_zhongxue :R.drawable.img_zhongxue;
                    break;
                case "99":
                    drawable =  isNight ? R.drawable.img_daxue :R.drawable.img_daxue;
                    break;
                case "大雪":
                    drawable =  isNight ? R.drawable.img_daxue :R.drawable.img_daxue;
                    break;
                case "19":
                    drawable = isNight ? R.drawable.img_bingbao :R.drawable.img_bingbao;
                    break;
                case "30":
                    drawable =  isNight ?R.drawable.img_sha : R.drawable.img_sha;
                    break;
                case "沙":
                    drawable =  isNight ?R.drawable.img_sha : R.drawable.img_sha;
                    break;
                case "20":
                    drawable =  isNight ? R.drawable.img_wu :R.drawable.img_wu;
                    break;
                case "雾":
                    drawable =  isNight ? R.drawable.img_wu :R.drawable.img_wu;
                    break;
                case "32":
                    drawable =isNight ? R.drawable.img_mai : R.drawable.img_mai;
                    break;
                case "日落":
                    drawable = R.drawable.img_riluo;
                  
                    break;
                case "日出":
                    drawable = R.drawable.img_richu;
                    break;
                default:
                    if(weatherState.length()>2){
                        String firstText = weatherState.substring(0,1)+"";
                        String secondText = weatherState.substring(0,2)+"";
                        switch (firstText){
                            case "晴":
                                drawable =isNight ? R.drawable.img_taiyang : R.drawable.img_taiyang;
                                break;
                            case "阴":
                                drawable =isNight ? R.drawable.img_yintian : R.drawable.img_yintian;
                                break;
                            case "阵":
                                drawable =isNight ? R.drawable.img_dayu : R.drawable.img_dayu;
                                break;
                            case "雷":
                                drawable =isNight ? R.drawable.img_dayu : R.drawable.img_dayu;
                                break;
                            case "多":
                                drawable =isNight ? R.drawable.img_duoyun : R.drawable.img_duoyun;
                                break;
                            default:
                                switch (secondText){
                                    case "小雨":
                                        drawable =isNight ? R.drawable.img_xiaoyu : R.drawable.img_xiaoyu;
                                        break;
                                    case "大雨":
                                        drawable =isNight ? R.drawable.img_dayu : R.drawable.img_dayu;
                                        break;
                                    case "小雪":
                                        drawable =isNight ? R.drawable.img_xiaoxue : R.drawable.img_xiaoxue;
                                        break;
                                    case "大雪":
                                        drawable =isNight ? R.drawable.img_daxue : R.drawable.img_daxue;
                                        break;
                                    case "中雨":
                                        drawable =isNight ? R.drawable.img_dayu : R.drawable.img_dayu;
                                        break;
                                    case "中雪":
                                        drawable =isNight ? R.drawable.img_daxue : R.drawable.img_daxue;
                                        break;
                                    default:
                                        drawable =isNight ? R.drawable.img_yintian : R.drawable.img_yintian;
                                        break;
                                }

                                break;
                        }
                    }else {
                        drawable =isNight ? R.drawable.img_yintian : R.drawable.img_yintian;
                    }
                    break;
            }
        }
      
        
        return drawable;
    }

    /**
     * 天气小图
     * @param WeatherState
     * @param isNight
     * @return
     */
    public static Integer getWeatherSmallImage(String WeatherState, boolean isNight) {

        int drawable = 0;
        if (TextUtils.isEmpty(WeatherState)) {
            drawable =isNight ? R.drawable.img_taiyang: R.drawable.img_taiyang;

        } else {
            switch (WeatherState) {
                case "0":
                    drawable =isNight ? R.drawable.img_weather_taiyang_24:R.drawable.img_weather_taiyang_24;
                    break;
                case "晴":
                    drawable =isNight ? R.drawable.img_weather_taiyang_24:R.drawable.img_weather_taiyang_24;
                    break;
                case "多云":
                    drawable =isNight ? R.drawable.img_weather_duoyun_24:R.drawable.img_weather_duoyun_24;
                    break;
                case "小雨":
                    drawable =isNight ? R.drawable.img_weather_xue_24:R.drawable.img_weather_xue_24;
                    break;
                case "阴":
                    drawable =isNight ? R.drawable.img_weather_yin_24:R.drawable.img_weather_yin_24;
                    break;
                case "小雪":
                    drawable =isNight ? R.drawable.img_weather_xue_24:R.drawable.img_weather_xue_24;
                    break;
                case "1":
                    drawable = isNight ? R.drawable.img_weather_duoyun_24:R.drawable.img_weather_duoyun_24;

                    break;
                case "2":
                    drawable = isNight ? R.drawable.img_weather_yin_24:R.drawable.img_weather_yin_24;

                    break;

                case "3":
                    drawable =  isNight ? R.drawable.img_weather_dayu_24 :R.drawable.img_weather_dayu_24;

                    break;
                case "雷雨":
                    drawable =  isNight ? R.drawable.img_weather_dayu_24 :R.drawable.img_weather_dayu_24;

                    break;
                case "暴雨":
                    drawable =  isNight ? R.drawable.img_weather_dayu_24 :R.drawable.img_weather_dayu_24;
                    break;
                case "冰雹":
                    drawable =  isNight ? R.drawable.img_weather_xue_24 :R.drawable.img_weather_xue_24;
                    break;
                case "4":
                    drawable =  isNight ? R.drawable.img_weather_dayu_24 :R.drawable.img_weather_dayu_24;
                    break;
                case "雷阵雨":
                    drawable =  isNight ? R.drawable.img_weather_dayu_24 :R.drawable.img_weather_dayu_24;
                    break;
                case "6":
                    drawable =  isNight ? R.drawable.img_weather_xue_24:R.drawable.img_weather_xue_24;
                    break;
                case "雨夹雪":
                    drawable =  isNight ? R.drawable.img_weather_xue_24 :R.drawable.img_weather_xue_24;
                    break;
                case "冻雨":
                    drawable = isNight ? R.drawable.img_weather_dayu_24 :R.drawable.img_weather_dayu_24;
                    break;
                case "7":
                    drawable = isNight ? R.drawable.img_weather_dayu_24 : R.drawable.img_weather_dayu_24;
                    break;
                case "8"://也就是中雨
                    drawable =isNight ? R.drawable.img_weather_dayu_24 : R.drawable.img_weather_dayu_24;
                    break;
                case "中雨":
                    drawable =isNight ? R.drawable.img_weather_dayu_24 : R.drawable.img_weather_dayu_24;
                    break;
                case "9":
                    drawable =isNight ? R.drawable.img_weather_dayu_24 :  R.drawable.img_weather_dayu_24;
                    break;
                case "大雨":
                    drawable =isNight ? R.drawable.img_weather_dayu_24 : R.drawable.img_weather_dayu_24;
                    break;
                case "10":
                    drawable = isNight ? R.drawable.img_weather_dayu_24 :R.drawable.img_weather_dayu_24;
                    break;
                case "14":
                    drawable = isNight ? R.drawable.img_weather_xue_24 :R.drawable.img_weather_xue_24;
                    break;

                case "雪":
                    drawable = isNight ? R.drawable.img_weather_xue_24 :R.drawable.img_weather_xue_24;

                    break;
                case "15":
                    drawable = isNight ? R.drawable.img_weather_xue_24 :R.drawable.img_weather_xue_24;
                    break;
                case "中雪":
                    drawable = isNight ? R.drawable.img_weather_xue_24 :R.drawable.img_weather_xue_24;
                    break;
                case "99":
                    drawable =  isNight ? R.drawable.img_weather_xue_24 :R.drawable.img_weather_xue_24;
                    break;
                case "大雪":
                    drawable =  isNight ? R.drawable.img_weather_xue_24 :R.drawable.img_weather_xue_24;
                    break;
                case "19":
                    drawable = isNight ? R.drawable.img_weather_xue_24 :R.drawable.img_weather_xue_24;
                    break;
                case "30":
                    drawable =  isNight ?R.drawable.img_weather_yin_24 : R.drawable.img_weather_yin_24;
                    break;
                case "沙":
                    drawable =  isNight ?R.drawable.img_weather_wu_24 : R.drawable.img_weather_wu_24;
                    break;
                case "20":
                    drawable =  isNight ? R.drawable.img_weather_wu_24 :R.drawable.img_weather_wu_24;
                    break;
                case "雾":
                    drawable =  isNight ? R.drawable.img_weather_wu_24 :R.drawable.img_weather_wu_24;
                    break;
                case "32":
                    drawable =isNight ? R.drawable.img_weather_wu_24 : R.drawable.img_weather_wu_24;
                    break;
                case "日落":
                    drawable = R.drawable.img_weather_taiyang_24;
                    break;
                case "日出":
                    drawable = R.drawable.img_weather_taiyang_24;
                    break;
                default:
                    drawable =isNight ? R.drawable.img_weather_yin_24 : R.drawable.img_weather_yin_24;
                    break;
            }
        }


        return drawable;
    }
    /**
     * 数字转对应的文字
     *
     * @param weatherNumber
     * @return
     */
    public static String getWeatherState(int weatherNumber) {
        String weatherState = "";
        switch (weatherNumber) {
            case 0:
                weatherState = "晴";
                break;
            case 1:
                weatherState = "多云";
                break;
            case 2:
                weatherState = "阴";
                break;
            case 3:
                weatherState = "阵雨";
                break;
            case 4:
                weatherState = "雷阵雨";
                break;
            case 6:
                weatherState = "雨夹雪";
                break;
            case 7:
                weatherState = "小雨";
                break;
            case 8:
                weatherState = "雨";

                break;
            case 9:
                weatherState = "大雨";
                break;
            case 10:
                weatherState = "暴雨";
                break;
            case 14:
                weatherState = "小雪";
                break;
            case 15:
                weatherState = "雪";
                break;
            case 19:
                weatherState = "雹";
                break;
            case 20:
                weatherState = "雾";
                break;
            case 30:
                weatherState = "沙";
                break;
            case 32:
                weatherState = "霾";
                break;
            case 99:
                weatherState = "大雪";
                break;
            default:
                weatherState = "晴";
                break;
        }
        return weatherState;
    }






}
